package me.zhengjie.gas.proto.send;

import me.zhengjie.gas.proto.TankerComm;

import java.util.Calendar;

/**
 * 正常轮询指令B0，发送交易记录
 */
public class B0Comm extends TankerComm {
    // 黑名单版本号
    private byte HMD;

    // 油价版本号
    private byte PRC;

    public B0Comm() {
        Cmd = (byte) 0xB0;
    }

    public void setHMD(byte HMD) {
        this.HMD = HMD;
    }

    public void setPRC(byte PRC) {
        this.PRC = PRC;
    }

    @Override
    public byte[] encode() {
        byte[] data = new byte[9];
        data[0] = Cmd;
        Calendar cal = Calendar.getInstance();
        // 年
        int year = cal.get(Calendar.YEAR);
        byte a1 = (byte) ((year % 100) / 10);
        byte a2 = (byte) (year % 10);
        data[1] = (byte) ((a1 << 4) | a2);

        // 月
        int month = cal.get(Calendar.MONTH) + 1;
        a1 = (byte) (month / 10);
        a2 = (byte) (month % 10);
        data[2] = (byte) ((a1 << 4) | a2);

        // 日
        int day = cal.get(Calendar.DAY_OF_MONTH);
        a1 = (byte) (day / 10);
        a2 = (byte) (day % 10);
        data[3] = (byte) ((a1 << 4) | a2);

        // 时
        int hour = cal.get(Calendar.HOUR_OF_DAY);
        a1 = (byte) (hour / 10);
        a2 = (byte) (hour % 10);
        data[4] = (byte) ((a1 << 4) | a2);

        // 分
        int minute = cal.get(Calendar.MINUTE);
        a1 = (byte) (minute / 10);
        a2 = (byte) (minute % 10);
        data[5] = (byte) ((a1 << 4) | a2);

        // 秒
        int second = cal.get(Calendar.SECOND);
        a1 = (byte) (second / 10);
        a2 = (byte) (second % 10);
        data[6] = (byte) ((a1 << 4) | a2);

        data[7] = HMD;
        data[8] = PRC;

        setDATA(data);
        return super.encode();
    }

    public byte getHMD() {
        return HMD;
    }

    public byte getPRC() {
        return PRC;
    }
}
